<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="12">
        <a-col :md="4" :sm="8">
            <a-form-item label="工作站名称">
              <a-select v-model="queryParam.workName" :options="workNameOptions"></a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="操作员名字">
              <a-select v-model="queryParam.operationName" :options="operationNameOptions"></a-select>
            </a-form-item>
          </a-col>
         <a-col :md="4" :sm="8">
           <a-form-item label="上班日期">
             <a-date-picker show-time placeholder="起始时间" value-format="yyyy-MM-dd HH:mm:ss" @change="onChangeUpStartTime" />
           </a-form-item >
         </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="至">
              <a-date-picker show-time placeholder="截止时间" value-format="yyyy-MM-dd HH:mm:ss" @change="onChangeUpEndTime" />
            </a-form-item >
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="交/下班日期">
              <a-date-picker show-time placeholder="起始时间" value-format="yyyy-MM-dd HH:mm:ss" @change="onChangeOverStartTime" />
            </a-form-item >
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="至">
              <a-date-picker show-time placeholder="截止时间" value-format="yyyy-MM-dd HH:mm:ss" @change="onChangeOverEndTime" />
            </a-form-item >
          </a-col>
          <a-col :md="4" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('交接班')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
                <a @click="handleDetail(record)">详情</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <parkHandOverLog-modal ref="modalForm" @ok="modalFormOk"></parkHandOverLog-modal>
  </a-card>
</template>

<script>
  import ParkHandOverLogModal from './modules/ParkHandOverLogModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {deleteAction, getAction, downFile} from '@/api/manage'
  import { filterObj } from '@/utils/util';

  export default {
    name: "ParkHandOverLogList",
    mixins:[JeecgListMixin],
    components: {
      ParkHandOverLogModal
    },
    data () {
      return {
        description: '交接班管理页面',
        // 表头
        columns: [
		   {
            title: '工作站名称',
            align:"center",
            dataIndex: 'workName'
           },
		   {
            title: '当班操作员名称',
            align:"center",
            dataIndex: 'realName'
           },
		   {
            title: '接班操作员名称',
            align:"center",
            dataIndex: 'handOverName'
       },
		   {
            title: '上班时间',
            align:"center",
            dataIndex: 'upTime'
           },
		   {
            title: '交/下班时间',
            align:"center",
            dataIndex: 'overTime'
           },
		   {
            title: '人工应收金额(元)',
            align:"center",
            dataIndex: 'manualReceivable'
           },
		   {
            title: '人工实收金额(元)',
            align:"center",
            dataIndex: 'manualPaid'
           },
		   {
            title: '人工免费金额(元)',
            align:"center",
            dataIndex: 'manualFree'
           },
		   {
            title: '电子支付应收金额(元)',
            align:"center",
            dataIndex: 'onlineReceivable'
           },
		   {
            title: '电子支付实收金额(元)',
            align:"center",
            dataIndex: 'onlinePaid'
           },
		   {
            title: '电子支付免费金额(元)',
            align:"center",
            dataIndex: 'onlineFree'
           },
		   {
            title: '总放行数',
            align:"center",
            dataIndex: 'allOutNum'
           },
		   {
            title: '正常收费放行数',
            align:"center",
            dataIndex: 'normalFeeOut'
           },
		   {
            title: '正常自动放行数',
            align:"center",
            dataIndex: 'normalNoFeeOut'
           },
		   {
            title: '免费放行数',
            align:"center",
            dataIndex: 'freeOut'
           },
		   {
            title: '异常放行数',
            align:"center",
            dataIndex: 'abnormalOut'
           },
          {
              title: '创建时间',
              align:"center",
              dataIndex: 'createTime'
             },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        workNameOptions:[],
        operationNameOptions:[],
		url: {
          list: "/operationLog/parkHandOverLog/list",
          delete: "/operationLog/parkHandOverLog/delete",
          deleteBatch: "/operationLog/parkHandOverLog/deleteBatch",
          exportXlsUrl: "operationLog/parkHandOverLog/exportXls",
          importExcelUrl: "operationLog/parkHandOverLog/importExcel",
          workNameLoad: "operationLog/parkHandOverLog/getWorkList",
          operationNameLoad:"operationLog/parkHandOverLog/getOperationList"
    },
       queryParam: {
         "workName":"",
         "username":"",
              },
              isorter:{
               column: 'createTime',
               order: 'desc',
             },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
   created(){
        this.workNameData();
        this.operationNameData();
         this.keyupEnter()
   },
    methods: {
      workNameData(){
        getAction(this.url.workNameLoad).then(res=>{
          if(res.result) {
            this.workNameOptions = [{value:'',label:'请选择工作站'}]
            res.result.forEach(work=>{
              this.workNameOptions.push({
                key:work.id,
                label:work.workName,
                value:work.workName
              })
            })
          }else {
            this.$message.error(res.message)
          }
        })
      },
      operationNameData(){
        getAction(this.url.operationNameLoad).then(res=>{
          if(res.result) {
            this.operationNameOptions = [{value:'',label:'请选择操作员'}]
            res.result.forEach(operation=>{
              this.operationNameOptions.push({
                key:operation.id,
                label:operation.realname,
                value:operation.username
              })
            })
          }else {
            this.$message.error(res.message)
          }
        })
      },

      handleExportXls(fileName){

          downFile(this.url.exportXlsUrl).then((data)=>{
            if (!data) {
              this.$message.warning("文件下载失败")
              return
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
              window.navigator.msSaveBlob(new Blob([data]), fileName+'.xls')
            }else{
              let url = window.URL.createObjectURL(new Blob([data]))
              let link = document.createElement('a')
              link.style.display = 'none'
              link.href = url
              link.setAttribute('download', fileName+'.xls')
              document.body.appendChild(link)
              link.click()
              document.body.removeChild(link); //下载完成移除元素
              window.URL.revokeObjectURL(url); //释放掉blob对象
            }
          })
        },


      onChangeUpStartTime(date, dateString) {
        this.queryParam.upStartTime = dateString;
      },

      onChangeUpEndTime(date, dateString) {
        this.queryParam.upEndTime = dateString;
      },

      onChangeOverStartTime(date, dateString) {
        this.queryParam.overStartTime = dateString;
      },

      onChangeOverEndTime(date, dateString) {
        this.queryParam.overEndTime = dateString;
      },
        loadData(arg) {
          if(!this.url.list){
            this.$message.error("请设置url.list属性!")
            return
          }
          //加载数据 若传入参数1则加载第一页的内容
          if (arg === 1) {
            this.ipagination.current = 1;
          }
          var params = this.getQueryParams();//查询条件
          this.loading = true;
          getAction(this.url.list, params).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records;
              this.ipagination.total = res.result.total;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
            this.loading = false;
          })
        },

        searchQuery() {

                this.loadData(1);
            },

                getQueryParams(){

                var param = Object.assign({}, this.isorter, this.queryParam);
                param.field = this.getQueryField();
                param.pageNo = this.ipagination.current;
                param.pageSize = this.ipagination.pageSize;

                return filterObj(param);
              },

              batchDel: function () {

              if(!this.url.deleteBatch){
                this.$message.error("请设置url.deleteBatch属性!")
                return
              }
              if (this.selectedRowKeys.length <= 0) {
                this.$message.warning('请选择一条记录！');
                return;
              } else {
                var ids = "";
                for (var a = 0; a < this.selectionRows.length; a++) {
                  ids += this.selectionRows[a].invateuserdetailId + ",";
                }
                var that = this;
                this.$confirm({
                  title: "确认删除",
                  content: "是否删除选中数据?",
                  onOk: function () {
                    deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
                      if (res.success) {
                        that.$message.success(res.message);
                        that.loadData();
                        that.onClearSelected();
                      } else {
                        that.$message.warning(res.message);
                      }
                    });
                  }
                });
              }
            },
            handleDelete: function (invateuserdetailId) {
              if(!this.url.delete){
                this.$message.error("请设置url.delete属性!")
                return
              }
              var that = this;
              deleteAction(that.url.delete, {invateuserdetailId: invateuserdetailId}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                } else {
                  that.$message.warning(res.message);
                }
              });
            },


         keyupEnter(){
                    document.onkeydown = e =>{
                        let body = document.getElementsByTagName('body')[0]
                        if (e.keyCode === 13  ) {
                           this.loadData(1);
                        }
                    }
                },

        }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
